import Vue from 'vue'
import VueRouter from 'vue-router'
// 首页引入
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/detail',
    component: () =>import ( /* webpackChunkName: "detail" */ '../views/Detail.vue')
  },
  {
    path: '/record',
    component: () =>import ( /* webpackChunkName: "record" */ '../views/Record.vue')
  },
  {
    path: '/fytables',
    component: () =>import ( /* webpackChunkName: "fytables" */ '../views/Fytables.vue')
  },
  {
    path: '/myfile',
    component: () =>import ( /* webpackChunkName: "myfile" */ '../views/Myfile.vue')
  },
  {
    path: '/upimg',
    component: () =>import ( /* webpackChunkName: "upimg" */ '../views/Upimg.vue')
  },
  {
    path: '/vtable',
    component: () =>import ( /* webpackChunkName: "vtable" */ '../views/Vtable.vue')
  },
  // 修改用户名
  {
    path: '/personal',
    component: () =>import ( /* webpackChunkName: "personal" */ '../views/Personal.vue')
  },
  //跳转完善个人信息
    {
        path: '/Perfect',
        component: () =>import ( /* webpackChunkName: "Perfect" */ '../views/Perfect.vue')
    },
    // 疫苗科普
    {
        path: '/Knowledge',
        component: () =>import ( /* webpackChunkName: "Knowledge" */ '../views/Knowledge.vue')
    },
    {
        //跳转更多页面
        path: '/set',
        component: () =>import ( /* webpackChunkName: "more" */ '../views/Set.vue')
      },
      {
        //跳转更多页面
        path: '/mychat',
        component: () =>import ( /* webpackChunkName: "more" */ '../components/Mychat.vue')
      },
   {
    //跳转更多页面
    path: '/more',
    component: () =>import ( /* webpackChunkName: "more" */ '../views/More.vue')
  },
  {
    //跳转我的页面
    path: '/mypage',
    name: 'Mypage',
    component: () =>import ( /* webpackChunkName: "mypage" */ '../views/Mypage.vue')
  },
  {
    // 这是插槽？
    //跳转二维码页面
    path: '/myqrcode',
    name: 'Myqrcode',
    component: () =>import ( /* webpackChunkName: "myqrcode" */ '../views/Myqrcode.vue')
  },
  {
    // 这是插槽？
    //跳转意见反馈页面
    path: '/myfeedback',
    name: 'Myfeedback',
    component: () =>import ( /* webpackChunkName: "myfeedback" */ '../views/Myfeedback.vue')
  },
  {
    //跳转我的收藏页面
    path: '/mycollection',
    name: 'Mycollection',
    component: () =>import ( /* webpackChunkName: "mycollection" */ '../views/Mycollection.vue')
  },
  {
      //跳转健康方案页面
    path: '/myhealthy',
    name: 'Myhealthy',
    component: () =>import ( /* webpackChunkName: "myhealthy" */ '../components/other-tools/Myhealthy.vue')
  },
  
  {
    //跳转防疫插槽页面
    path: '/vmap',
    name: 'Vmap',
    component: () =>import ( /* webpackChunkName: "vmap" */ '../views/Vmap.vue')
},
{
    //跳转主地图页面
    path: '/fymap',
    name: 'Fymap',
    component: () =>
        import ( /* webpackChunkName: "fymap" */ '../views/Fymap.vue')
},
{
    //跳转折线图插槽页面
    path: '/lineChart',
    name: 'LineChart',
    component: () =>
        import ( /* webpackChunkName: "lineChart" */ '../views/LineChart.vue')
},
{
    //跳转忘记密码页面
    path: '/forgetpwd',
    component: () =>
        import ( /* webpackChunkName: "forgetpwd" */ '../views/Forgetpwd.vue')
},
{
    //跳转验证码页面
    path: '/code',
    component: () =>
        import ( /* webpackChunkName: "code" */ '../views/Code.vue')
},
{
    //跳转登录页面
    path: '/login',
    component: () =>import ( /* webpackChunkName: "login" */ '../views/Login.vue')
},
{
    //跳转注册页面
    path: '/register',
    component: () =>import ( /* webpackChunkName: "register" */ '../views/Register.vue')
},
{
    //跳转首页页面
    path: '/',
    name: 'Home',
    component: Home
},
{
    //跳转个人等级预约记录页面
    path: '/memock',
    name: 'Memock',
    component: () =>
        import ( /* webpackChunkName: "memock" */ '../views/Memock.vue')
},

{
    //跳转预约页面
    path: '/appointment',
    name: 'Appointment',
    component: () =>
        import ( /* webpackChunkName: "appointment" */ '../views/Appointment.vue')
},
{
    //跳转健康自评
    path: '/evaluation',
    name: 'Evaluation',
    component: () =>
        import ( /* webpackChunkName: "evaluation" */ '../views/Evaluation.vue')
},
{
    //跳转预防接种
    path: '/inoculation',
    name: 'Inoculation',
    component: () =>
        import ( /* webpackChunkName: "inoculation" */ '../views/Inoculation.vue')
},
{
    //跳转互联网医院
    path: '/hospital',
    name: 'Hospital',
    component: () =>
        import ( /* webpackChunkName: "hospital" */ '../views/Hospital.vue')
},
// 跳转服务界面
{
    path: '/service',
    name: 'Service',
    component: () =>
        import ( /* webpackChunkName: "service" */ '../views/Service.vue')
},
// 跳转咨询界面
{
    path: '/consult',
    name: 'Consult',
    component: () =>
        import ( /* webpackChunkName: "consult" */ '../views/Consult.vue')
},
// 跳转搜索界面
{
    path: '/search',
    name: 'Search',
    component: () =>
        import ( /* webpackChunkName: "search" */ '../views/Search.vue')
},
// 跳转预约界面
{
    path: '/subscribe',
    name: 'Subscribe',
    component: () =>
        import ( /* webpackChunkName: "subscribe" */ '../views/Subscribe.vue')
},
// 跳转健康码界面
{
    path: '/health-code',
    name: 'HealthCode',
    component: () =>
        import ( /* webpackChunkName: "health-code" */ '../views/HealthCode.vue')
},
{
    path:'/travel-code',
    name:'TravelCode',
    component:()=>import(/* webpackChunkName: "health-code" */ '../views/TravelCode.vue')
},
{
    path:'/travel-code',
    name:'TravelCode',
    component:()=>import(/* webpackChunkName: "health-code" */ '../views/TravelCode.vue')
},
{
    //跳转互联网医院
    path: '/hospital',
    name: 'Hospital',
    component: () => import('../views/Hospital.vue')
  },
  {
    //跳转自评回答
    path: '/myself',
    name: 'Myself',
    component: () => import('../views/Myself.vue')
  },
  {
    //跳转自评历史
    path: '/history',
    name: 'history',
    component: () => import('../views/History.vue')
  },
  {
    //跳转登记页
    path: '/mount',
    name: 'Mount',
    component: () => import('../views/Mount.vue')
  },
  {
    //跳转接种记录
    path: '/ckmemo',
    name: 'Ckmemo',
    component: () => import('../views/Ckmemo.vue')
  },
  {
    //跳转互联网医院
    path: '/appoin',
    name: 'Appoin',
    component: () => import('../views/Appoin.vue')
  },
  {
    //跳转互联网医院
    path: '/changeheade',
    name: 'Changeheade',
    component: () => import('../components/Changeheade.vue')
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//设置路由拦截
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
router.beforeEach((to, from, next) => {
  // console.log(to);
  let islogin = sessionStorage.getItem("islogin");
  let token = sessionStorage.getItem('token')  || "";
  console.log(token);
  if (to.name == "Appointment" || to.name == "Mypage" || to.name =="HealthCode" || to.name=="TravelCode"){

  if(token != '' ) {
      
        // if (to.name == "Appointment" || to.name =="HealthCode" || to.name=="TravelCode") {
      next();
      console.log(2);
    }else {
      // console.log(1);
      next({
        path:"/login",
        query:{redirect:to.fullPath}
      });
      
  }
}else {
  // console.log(3);
  next();
}
})

export default router
